package models

import (
	// "fmt"
	"github.com/beego/beego/v2/client/orm"
	beego "github.com/beego/beego/v2/server/web"
	_ "github.com/go-sql-driver/mysql"
)

var DbOrm orm.Ormer

func init() {
	orm.RegisterDriver("mysql", orm.DRMySQL)
	usr, _ := beego.AppConfig.String("mysqluser")
	pwd, _ := beego.AppConfig.String("mysqlpass")
	// orm.RegisterDataBase("default", "mysql", "root:xijing123456@/globalworld_player?charset=utf8")
	orm.RegisterDataBase("default", "mysql", usr+":"+pwd+"@/globalworld_player?charset=utf8")
	orm.RegisterModel(new(TAllGameserverInfo), new(TAllAccount))
	orm.RegisterModelWithPrefix("t_", new(Account), new(Server_info), new(ServerVersionData))
}

func GetNewOrm() orm.Ormer {
	if DbOrm == nil {
		DbOrm = orm.NewOrm()
	}

	return DbOrm
}
